package com.ibeifeng.crm.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;


import com.ibeifeng.crm.bean.Notice;

import com.ibeifeng.crm.dao.NoticeDao;

@Repository
public class NoticeDaoImpl implements NoticeDao{
	Logger log = Logger.getLogger(NoticeDaoImpl.class);
	
	@Resource
	SqlSessionFactory factory;
	@Override
	public List<Notice> queryAll() {
		List<Notice> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.NoticeNS.queryAll");
		return list;
	}
	@Override
	public int add(Notice notice) {
		int result = factory.openSession().insert("com.ibeifeng.crm.bean.mapping.NoticeNS.insert", notice);
		return result;
	}
	@Override
	public int update(Notice notice) {
		int result = factory.openSession().update("com.ibeifeng.crm.bean.mapping.NoticeNS.update", notice);
		return result;
	}
	@Override
	public int delete(Notice notice) {
		int result = factory.openSession().delete("com.ibeifeng.crm.bean.mapping.NoticeNS.delete", notice);
		
		return result;
	}
	@Override
	public Notice queryNotice(Notice notice) {
		Notice cou = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.NoticeNS.findById", notice);
		return cou;
	}
	@Override
	public int count() {
		int count = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.NoticeNS.count");
		return count;
	}
	@Override
	public List<Notice> findAllSplit(int pg, int pgSize) {
		Map map = new HashMap();
		int start=(pg-1)*pgSize;
		int pageSize = pgSize;
		map.put("start", start);
		map.put("pageSize", pgSize);
		List<Notice> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.NoticeNS.findAllSplit",map);
		return list;
	}
	@Override
	public List<Notice> mquery(int pg, int pgSize, String keyWord) {
		Map map = new HashMap();
		int start=(pg-1)*pgSize;
		int pageSize = pgSize;
		map.put("start", start);
		map.put("pageSize", pgSize);
		map.put("keyWord", keyWord);
		List<Notice> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.NoticeNS.mquery",map);
		return list;
	}
	
	

}
